package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.MoveBill;
import cn.wolfcode.crm.query.MoveBillQueryObject;
import cn.wolfcode.crm.service.IMoveBillService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("moveBill")
public class MoveBillController {

    @Autowired
    private IMoveBillService moveBillService;

    @RequestMapping("index")
    public String index(){
        return "moveBill/list";
    }

    @ResponseBody
    @RequestMapping("list")
    public PageResult index(MoveBillQueryObject qo){
        PageResult result = moveBillService.queryListByQo(qo);
        return result;
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(MoveBill moveBill){
        JsonResult result = new JsonResult();
        try {
            moveBillService.insert(moveBill);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存出错!");
        }
        return result;
    }


    @ResponseBody
    @RequestMapping("queryMoveBillByid")
    public MoveBill queryMoveBillByid(Long id){
        return moveBillService.selectByPrimaryKey(id);
    }

    @ResponseBody
    @RequestMapping("queryAllMoveBill")
    public List<MoveBill> queryAllMoveBill(){
        return moveBillService.selectAll();
    }
}
